package test5.lupeng.jf.com.teamdemo.widget;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import test5.lupeng.jf.com.teamdemo.R;

/**
 * Created by C-yx on 2017/7/27.
 */

public class TabView  extends LinearLayout{
    private  boolean TAG=false;
    private  String desStr;
    private int resId;
    private ImageView icon;
    private TextView textView;

    public TabView(Context context,String desStr,int resId) {
        super(context);
        this.desStr = desStr;
        this.resId= resId;
        initView();
    }

    public ImageView getIcon() {
        return icon;
    }


    public TextView getTextView() {
        return textView;
    }


    /**
     * 初始化视图
     */
    private  void initView(){
        setOrientation(VERTICAL);
        setGravity(Gravity.CENTER);

        //初始化图形
        icon = new ImageView(getContext());
        LinearLayout.LayoutParams iconParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        icon.setLayoutParams(iconParams);
        icon.setImageResource(resId);

        addView(icon);

        //初始化文字
        textView = new TextView(getContext());
        LinearLayout.LayoutParams tvParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        textView.setLayoutParams(tvParams);
        textView.setText(desStr);
        addView(textView);
    }

    public  void setSelected(boolean isSelect){
        TAG=isSelect;
        if(isSelect){
            if(icon!=null){
                icon.setColorFilter(getResources().getColor(R.color.toolbarColor));

            }
            if (textView!=null){
                textView.setTextColor(getResources().getColor(R.color.toolbarColor));
            }
        }else
        {
            if(icon!=null){
                icon.setColorFilter(Color.GRAY);
            }
            if (textView!=null){
                textView.setTextColor(Color.GRAY);
            }
        }
    }

    public  boolean isSelected(){
        return  TAG;
    }

}
